const Koa = require('koa');
const koaRouter = require('@koa/router');

const app = new Koa();
const userRouter = new koaRouter({ prefix: '/users' });

userRouter.get('/list', ctx => {
    console.log(ctx,'ctx');
  ctx.body = [
    { name: 'lyy', age: 23 },
    { name: 'gsy', age: 25 }
  ];
});

app.use((ctx,next)=>{
  ctx.set('Access-Control-Allow-Origin','*')
  console.log(ctx);
  next()
})

app.use(userRouter.routes());
app.use(userRouter.allowedMethods());

app.listen(9000, (res) => {
  console.log('koa  9000');
});
